package com.example.tianhao.zyfypt_413th.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.tianhao.zyfypt_413th.R;
import com.example.tianhao.zyfypt_413th.iface.RegisterListener;
import com.example.tianhao.zyfypt_413th.model.RegisterModel;

public class RegActivity extends AppCompatActivity implements View.OnClickListener{
    private EditText name, pwd, tel;
    private Button submit;
    RegisterListener registerListener = new RegisterListener() {
        @Override
        public void onResponse(String msg) {
            if(msg.equals("1")){
                System.out.println("result:"+msg);
                finish();
            }else{
                System.out.println("result:"+msg);
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(RegActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reg);
        Toast.makeText(this,"注册", Toast.LENGTH_SHORT).show();
        init();
    }

    private void init() {
        name = (EditText)findViewById(R.id.editText_regname);
        pwd = (EditText)findViewById(R.id.editText_regpass);
        tel = (EditText)findViewById(R.id.editText3_tele);
        submit = (Button)findViewById(R.id.btn_Reg);

        submit.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        System.out.println("注册——提交");
        RegisterModel registerModel = new RegisterModel();
        registerModel.getResult(name.getText().toString(), pwd.getText().toString(), tel.getText().toString(), registerListener);

    }
}
